<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="common/common_head :: commonHeader('高度关注物质清单')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="substanceForm" th:action="@{/svhc/list}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label>关注物质：</label>
                            <input type="text" name="svhc" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <label>中文名称:</label>
                            <input type="text" name="zhName" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <label>英文名称:</label>
                            <input type="text" name="enName" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <label>化学文摘号：</label>
                            <input type="text" name="casNo" autocomplete="off"/>
                        </li>

                        <li class="col-sm-3">
                            <button id="substanceSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i
                                    class="fa fa-search"></i>&nbsp;搜索
                            </button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置
                            </button>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="substanceToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="addSVhc()"
                   shiro:hasPermission="substance:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="toDelete()"
                shiro:hasPermission="substance:delete">
                    <i class="fa fa-trash-o"></i> 删除
                </a>
            </div>
            <table id="substance" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<script type="text/javascript">

    var searcherBS = Searcher.createBS('#substance',
        [
            {checkbox: true},
            {title: '高度关注物质', field: 'svhc'},
            {title: '中文名称', field: 'zhName'},
            {title: '英文名称', field: 'enName'},
            {title: '化学文摘号', field: 'casNo'},
            {title: '添加人', field: 'creator'},
            {title: '添加时间', field: 'createDate'}

        ]
    );

    /**
     * 查询数据
     */
    function refresh() {
        searcherBS.refresh();
    }

    /**
     * 跳转至新增页
     */
    function addSVhc() {
        var index = Dialog.openUrl("新增", ctxPath + '/svhc/addSVhc', {
            area: ['900px', '700px'],
            maxmin: true,
            end: function () {
            }
        });
        layer.full(index);
    }

    /**
     * 删除
     */
    function toDelete() {
        var rowData = searcherBS.getRawData();
        if (rowData.length == 0) {
            Dialog.errorMsg("请选择要删除的物质！");
            return;
        }
        var itemIds = new Array();
        for (var i in rowData) {
            itemIds.push(rowData[i].pkId);
        }
        $.ajax({
            type: "get",
            url: ctxPath + "/svhc/deleteSvhc?itemIds=" + itemIds,
            contentType: "application/json;charsetset=UTF-8",//必须
            cache: false, // 不缓存
            success: function (data) {
                layer.closeAll();
                if (data.code == 500) {
                    Dialog.errorMsg("修改失败！");
                } else {
                    Dialog.msg("操作成功!");
                }
                searcherBS.refresh();
            },
            error: function (data) {
                layer.closeAll();
                Dialog.errorMsg("修改失败！");
            }
        });
    }

</script>

</body>
</html>